home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / RTF / xtextview.h < prev   
C/C++ Source or Header  |  1994-08-01  |  4KB  |  172 lines

  1. /* $Header: /usr/people/pcd/Src/RTF/RCS/xtextview.h,v 1.1 92/11/23 12:58:53 pcd Exp Locker: pcd $
  2.  */
  3.  
  4. #ifndef __xtextview_h
  5. #define __xtextview_h
  6.  
  7. #include "view.h"
  8. #include "textflow.h"
  9. #include "textrect.h"
  10.  
  11. #include <X11/Xlib.h>
  12. #include <assert.h>
  13.  
  14. typedef unsigned long Pixel;
  15.  
  16. class XTextFlow;
  17. class XNewLineFlow;
  18.  
  19. class XTextView : public View{
  20. friend class XTextFlow;
  21. friend class XBitMap;
  22.  
  23. public:
  24.   XTextView(Display&, void* widget);
  25.  
  26.   virtual Coord       hinches(double i) const
  27.     { return (Coord)((double)i * 254/10 * xdpmm()); }; //@@ make this tunable.
  28.  
  29.   virtual Coord       vinches(double i) const
  30.     { return (Coord)((double)i * 254/10 * ydpmm()); }; //@@ make this tunable.
  31.  
  32.   void text_flow(TextFlow& parent, TextPosition f, TextPosition l,
  33.          const CharacterFormat&);
  34.   void text_char(TextFlow& parent, TextPosition f, TextPosition l, char c,
  35.          const CharacterFormat&);
  36.   void new_line(TextFlow& parent, TextPosition f, TextPosition l,
  37.         Inches space_after);
  38.   void picture(TextFlow& parent, TextPosition f, TextPosition l,
  39.            Coord width, Coord height);
  40.  
  41.   int         render(Coord, Coord, Coord, Coord);
  42.  
  43.   int         region(TextPosition f, TextPosition l, Coord x[4], Coord y[4]);
  44.   int         locate(TextPosition pos, int* top, int* bot);
  45.  
  46.   Display*    display() const
  47.     { return display_; };
  48.  
  49.   XFontStruct* font(char* spec) const;
  50.  
  51.   GC get_gc(unsigned long mask, XGCValues& v);
  52.   void free_gc(GC gc);
  53.  
  54.   Pixel       color(int red, int green, int blue) const;
  55.  
  56.   GC          default_gc()
  57.     { return DefaultGC(display(), DefaultScreen(display())); };
  58.  
  59.   Pixel       black()
  60.     { return BlackPixel(display(), DefaultScreen(display())); };
  61.  
  62.   Pixel       white()
  63.     { return WhitePixel(display(), DefaultScreen(display())); };
  64.  
  65.   void        drawable(Drawable, unsigned int depth);
  66.  
  67. protected:
  68.   void clear();
  69.  
  70.   double      xdpmm() const
  71.     { return (double)WidthOfScreen(DefaultScreenOfDisplay(display())) /
  72.     WidthMMOfScreen(DefaultScreenOfDisplay(display())); };
  73.  
  74.   double      ydpmm() const
  75.     { return (double)HeightOfScreen(DefaultScreenOfDisplay(display())) /
  76.     HeightMMOfScreen(DefaultScreenOfDisplay(display())); };
  77.  
  78.   Drawable    drawable() const
  79.     { return drawable_; }; //@# what about 0?
  80.  
  81.   unsigned int depth() const
  82.     { /*assert(drawable_);*/
  83.       return depth_; };
  84.  
  85. private:
  86.   Display*  display_;
  87.   Drawable  drawable_;
  88.   int       depth_;
  89.   void*     widget_;
  90. };
  91.  
  92.  
  93. class XTextFlow : public TextFlow{
  94. public:
  95.   XTextFlow(TextFlow& parent, TextPosition first, TextPosition last,
  96.         XTextView& view, const CharacterFormat&, char c=0);
  97.   
  98.   ~XTextFlow();
  99.  
  100.   Qty character_shape(TextPosition, Qty, Extent, Extent&, int) const;
  101.  
  102.   void render(TextPosition, Qty, Point) const;
  103.  
  104. protected:
  105.  
  106.   XFontStruct* font() const
  107.     { return font_; };
  108.  
  109.   Display *    display() const
  110.     { return view_->display(); };
  111.  
  112.   Drawable     drawable() const
  113.     { return view_->drawable(); };
  114.   
  115.   GC           gc() const
  116.     { return gc_; };
  117.  
  118. private:
  119.   XTextView* view_;
  120.   char c_;
  121.   char ul_, super_, sub_;
  122.   void width(int w)
  123.     { width_ = w; };
  124.   int width_;
  125.   GC gc_;
  126.   XFontStruct* font_;
  127. };
  128.  
  129. class XNewLineFlow : public NewLineFlow{
  130. public:
  131.   XNewLineFlow(TextFlow& parent, TextPosition first, TextPosition last,
  132.            XTextView& view, Inches sa)
  133.     : NewLineFlow(parent, first, last)
  134.       { view_ = &view; space_after_ = sa; };
  135.  
  136.   Coord font_ascent() const
  137.     { return 10; };    //@@ use character formatting info !
  138.  
  139.   Coord space_after() const
  140.     { return view_->vinches(space_after_); };
  141.  
  142. private:
  143.   XTextView* view_;
  144.   Inches space_after_;
  145. };
  146.  
  147.  
  148. class XBitMap : public TextFlow{
  149. public:
  150.   XBitMap(TextFlow& p, TextPosition f, TextPosition l,
  151.       XTextView& v, int width, int height);
  152.  
  153.   ~XBitMap();
  154.  
  155.   Qty character_shape(TextPosition, Qty, Extent, Extent&, int) const;
  156.  
  157.   void render(TextPosition, Qty, Point) const;
  158.  
  159.   const XTextView* view() const
  160.     { return view_; };
  161.  
  162. private:
  163.   int get_pixmap();
  164.   XTextView* view_;
  165.   Coord width_;
  166.   Coord height_;
  167.   Pixmap pixmap_;
  168. };
  169.  
  170. #endif
  171.  
  172.